package com.six.backend.ws;

import org.apache.catalina.session.StandardSessionFacade;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @Author: skyler
 * @Date: 2021/11/14 21:32
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        //将httpSession对象存储到配置对象中
        if (httpSession!=null){
            System.out.println("获取到session id:"+httpSession.getId());
            sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
        }else{
            System.out.println("modifyHandshake 获取到null session");
        }
    }
}
